package org.takeback.chat.service.admin;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.util.WebUtils;
import org.takeback.core.service.MyListService;
import org.takeback.dao.BaseDAO;
import org.takeback.util.context.Context;
import org.takeback.util.context.ContextUtils;

@Service("manualChargeService")
public class ManualChargeService extends MyListService {
	@Transactional
	public void save(Map<String, Object> req) {
		Map<String, Object> data = (Map) req.get("data");
		Integer id = Integer.valueOf((String) data.get("id"));

		String hql1 = "select status from PubRecharge where id=" + id;
		String status = (String) this.dao.getUnique(hql1, new Object[0]);
		if ("1".equals(status)) {
			data.put("status", "2");
			HttpServletRequest request = (HttpServletRequest) ContextUtils.get(Context.HTTP_REQUEST);
			data.put("operator", WebUtils.getSessionAttribute(request, Context.UID));
            Integer uid = (Integer) data.get("uid");
            String tradeno = (String) data.get("tradeno");
            Double fee = (data.get("fee") == null) ? 0.0 : (double) data.get("fee");
            Double gift = (data.get("gift") == null) ? 0.0 : (double) data.get("gift");
			String hql = "update PubUser set money = COALESCE(money,0) + :add where id=:uid";
			Map<String, Object> param = new HashMap();
            param.put("add", fee + gift);
			param.put("uid", uid);
			this.dao.executeUpdate(hql, param);

			super.save(req);
		}
	}
}
